import { _decorator, Component, Node ,
    log,
    Mat4,
    mat4,
    Quat,
    quat,
    Vec3,
    v3,
    Vec2,
    v2
} from 'cc';
const { ccclass, property } = _decorator;


//---------------------
// temp
const v2_1 = v2();
const v3_1 = v3();


@ccclass('TestForward')
export class TestForward extends Component {
    /* class member could be defined like this */
    // dummy = '';

    /* use `property` decorator if your want the member to be serializable */
    // @property
    // serializableDummy = 0;

    @property({type:Node})
    nd_arrow:Node = null;

    @property({type:Node})
    nd_ball:Node = null;

    start () {
        let forward = this.nd_ball.forward;
        log('forward:',forward);
        this.node.on(Node.EventType.TOUCH_MOVE,this.touchMove,this);
    }

    touchMove(touch){
        log('touchMove called!');
        touch.getDelta(v2_1);

        if(Math.abs(v2_1.x) > Math.abs(v2_1.y)){
            // 绕y轴旋转
            if(Math.abs(v2_1.x) > 0){
                let angles = this.nd_ball.eulerAngles;
                Vec3.add(v3_1,angles,v3(0,v2_1.x / 10,0));
                this.nd_ball.eulerAngles = v3_1;
            }
        }else{
            // 绕z轴旋转
            if(Math.abs(v2_1.y) > 0){
                let angles = this.nd_ball.eulerAngles;
                Vec3.add(v3_1,angles,v3(0,0,-v2_1.y/10));
                this.nd_ball.eulerAngles = v3_1;
            }
        }
    }

    // update (deltaTime: number) {
    //     // Your update function goes here.
    // }
}
